/*
                    Statbar Class Definition
*/

#ifndef STATBAR_H
#define STATBAR_H

#include <stdio.h>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <string>

#include "../Structs.h"
#include "../Functions.h"

#include "Widget.h"

using namespace std;

struct Bar
{
    Bar() : Image(NULL) , iActivates(0), Position(0, 0) {}

    Bar(const int& iNewActivates, const string& strFilepath, Point NewPosition)
    {
        Image = IMG_Load(strFilepath.c_str());
        iActivates = iNewActivates;
        Position = NewPosition;
    }

    ~Bar() { SDL_FreeSurface(Image); }

    SDL_Surface *Image;
    int iActivates;
    Point Position;
};

class Statbar : public Widget
{
    public:
        Statbar();
        ~Statbar();

        int Initialise(Point NewPosition, Bar* pBar, const int& iNewMaxVal, const int& iNewCurVal, const string& strFilepath);

        int BlitToSurface(SDL_Surface *surface);
        int BlitToFrame(SDL_Surface *surface, Point FramePosition);

        int AddBar(Bar* pNew);

        void setPosition(Point NewPosition);
        Point getPosition();

        void setCurrentValue(const int& iValue);
        int getCurrentValue();

        void setMaxValue(const int& iValue);
        int getMaxValue();

        void OffsetValue(const int& iAmount);

        void CalculateBars();

    private:
        int iMaxValue;
        int iCurrentValue;
        float fCurrentPercent;

        vector<Bar*> Bars;

        SDL_Surface *Background;

        int iCurrentBar;
        int iCurrentWidth;

        Point Position;
};

#endif
